import GameConfig from "./GameConfig";
import GameWx from "./GameWx";
import GameEvent from "./GameEvent";
import { ui } from "./ui/layaMaxUI";
import MyUi from "./MyUi";
import WxUserInfo from "./WxObje/WxUserInfo";
import MaoLineData from "./MaoLineData";
import MaoRandom from "./MaoRandom";
import Bullet from "./Bullet";
import GameCore from "./GameCore";
import HomeUI from "./HomeUI";
import Gstatic from "./gameobj/Gstatic";
class Main {


	mui: MyUi;

	constructor() {
		//根据IDE设置初始化引擎		
		if (window["Laya3D"]) Laya3D.init(GameConfig.width, GameConfig.height);
		else Laya.init(GameConfig.width, GameConfig.height, Laya["WebGL"]);
		Laya["Physics"] && Laya["Physics"].enable();
		Laya["DebugPanel"] && Laya["DebugPanel"].enable();
		Laya.stage.scaleMode = GameConfig.scaleMode;
		Laya.stage.screenMode = GameConfig.screenMode;
		Laya.stage.alignV = GameConfig.alignV;
		Laya.stage.alignH = GameConfig.alignH;
		//兼容微信不支持加载scene后缀场景
		Laya.URL.exportSceneToJson = GameConfig.exportSceneToJson;

		//打开调试面板（通过IDE设置调试模式，或者url地址增加debug=true参数，均可打开调试面板）
		if (GameConfig.debug || Laya.Utils.getQueryString("debug") == "true") Laya.enableDebugPanel();
		if (GameConfig.physicsDebug && Laya["PhysicsDebugDraw"]) Laya["PhysicsDebugDraw"].enable();
		if (GameConfig.stat) Laya.Stat.show();
		Laya.alertGlobalError = true;

		//激活资源版本控制，version.json由IDE发布功能自动生成，如果没有也不影响后续流程
		Laya.ResourceVersion.enable("version.json", Laya.Handler.create(this, this.onVersionLoaded), Laya.ResourceVersion.FILENAME_VERSION);
		//this.onConfigLoaded();
	}

	onVersionLoaded(): void {
		//激活大小图映射，加载小图的时候，如果发现小图在大图合集里面，则优先加载大图合集，而不是小图
		Laya.AtlasInfoManager.enable("fileconfig.json", Laya.Handler.create(this, this.onConfigLoaded));
	}

	public static sp: Laya.Sprite;
	onConfigLoaded(): void {

		Gstatic.init_();

		Main.sp = new Laya.Sprite();
		Laya.stage.addChild(Main.sp);
		if(!GameWx.I.userinfo){
			GameWx.I.on(GameEvent.Event_WX_UserInfo,this,this.userinfo_ok);
			GameWx.I.getUser();
			GameCore.I.initGame();
		}		
		//GameCore.I.start();
		// var objArr = [{id:9},{id:150},{id:0},{id:2}]
		// objArr.sort((a,b)=>{
		// 		return a.id - b.id;			
		// });
		// for (let i = 0; i < objArr.length; i++) {
		// 	const element = objArr[i];
		// 	console.log(element.id);
		// }
	}

	userinfo_ok(){
		GameWx.I.init_();
		Main.sp.addChild(HomeUI.I);
		
	}
}
//激活启动类
new Main();
